export interface ClassToggles {
  [K: string]: boolean
}

function classes(...names: (string | ClassToggles)[]) {
  const _names = names.map(item => typeof item === 'string' ? {[item]: true} : item);
  return Object.entries(Object.assign({}, ..._names))
    .filter(kv => kv[1])
    .map(kv => kv[0])
    .join(' ')
}

export interface ClassesOptions {
  extra: string | undefined
}

function scopedClassMaker(prefix: string) {
  return (name: string | ClassToggles, options: ClassesOptions) =>
    Object.entries(typeof name === 'string' ? {[name]: name} : name)
      .filter(kv => kv[1] !== false)
      .map(kv => kv[0])
      .map(name => [prefix, name]
        .filter(Boolean)
        .join('-'))
      .concat((options && options.extra) || [])
      .join(' ');
}


export default classes;

export {scopedClassMaker};